package com.atguigu.yygh.user.service.Impl;

import com.atguigu.yygh.cmn.client.DictFeignClient;
import com.atguigu.yygh.user.mapper.PatientMapper;
import com.atguigu.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haust.su.ghyy.enums.DictEnum;
import com.haust.su.ghyy.model.user.Patient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author haustsusu
 * @create 2023-05-07-13:42
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Autowired
    private DictFeignClient dictFeignClient;


    //获取就诊人列表
    @Override
    public List<Patient> findAllUserId(Long userId) {
        //根据userid查询
        QueryWrapper<Patient> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<Patient> patientList = baseMapper.selectList(wrapper);
        //通过远程调用,得到编码对应的具体内容,查询数据字典表内容
        patientList.stream().forEach(item->{
            //其他参数的封装
            this.packPatient(item);
        });
        return patientList;
    }


    //根据id查询就诊人的信息
    @Override
    public Patient getPatientId(long id) {

        //这里的patient数据不够完整
        Patient patient = baseMapper.selectById(id);
        //调用this.package
        Patient packPatient = this.packPatient(patient);
        //将封装的patient对象返回
        return packPatient;
    }


    //其他参数的封装
    private Patient packPatient(Patient patient) {
        //根据证件类型编号,获取证件类型
        String certificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
        //联系人证件类型
        String contactsCertificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),patient.getContactsCertificatesType());
        //省
        String provinceString = dictFeignClient.getName(patient.getProvinceCode());
        //市
        String cityString = dictFeignClient.getName(patient.getCityCode());
        //区
        String districtString = dictFeignClient.getName(patient.getDistrictCode());
        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("cityString", cityString);
        patient.getParam().put("districtString", districtString);
        //放到完整的地址中去
        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());
        //
        return patient;

    }
}
